package com.app.mapper;

import cn.hutool.json.JSONObject;
import com.app.model.AdminUserModel;
import com.app.model.IntegralRecordModel;
import com.app.model.UserModel;
import com.app.model.VoucherRecordModel;
import com.github.yulichang.base.MPJBaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface UserMapper extends MPJBaseMapper<UserModel> {
    @Select("select * from tb_user where open_id = #{openid}")
    UserModel getByOpenid(String openid);

    List<JSONObject> userConsumptionVoucherStatistics(@Param("userModel") AdminUserModel userModel);

    List<VoucherRecordModel> voucherRecordsUse(@Param("id") Integer id);

    List<VoucherRecordModel> voucherRecordsGet(@Param("id") Integer id);

    List<IntegralRecordModel> integralRecordsUse(@Param("id") Integer id);

    List<IntegralRecordModel> integralRecordsGet(@Param("id") Integer id);


    @Select("select t.*,ta.area,tc.city,tp.province\n" +
            "from tb_user t\n" +
            "left join tbc_areas ta on t.area_id = ta.area_id\n" +
            "left join tbc_cities tc on ta.city_id = tc.city_id\n" +
            "left join tbc_provinces tp on tc.province_id = tp.province_id \n" +
            "where t.id = #{userid} ")
    UserModel getUserInfoById(Integer userid);


    @Select("select u.* " +
            "from tb_user u " +
            "left join tb_invite_record r on r.invite_id = u.id " +
            "where r.quilt_invite_id = #{userid} ")
    UserModel getUserSuperiorById(Integer userid);


}
